package me.leiusual.sharing.ui.useraccount

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations.switchMap
import androidx.lifecycle.ViewModel
import me.leiusual.sharing.api.model.UserAccount
import me.leiusual.sharing.repository.UserAccountRepository
import me.leiusual.sharing.repository.model.Data
import me.leiusual.sharing.util.extension.toLiveData
import javax.inject.Inject

/**
 * author: leiusual
 * create on: 2019-08-06
 * description:
 */
class UserAccountViewModel @Inject constructor(
    private val userAccountRepository: UserAccountRepository
) : ViewModel() {

  // 列表

  private val _userAccountList = MutableLiveData<String>()
  val userAccountList: LiveData<Data<List<UserAccount>>> = switchMap(_userAccountList) {
    userAccountRepository.userAccountList(it).toLiveData()
  }

  fun userAccountList(type: String) {
    _userAccountList.value = type
  }
}